package cn.psvmc.cxzapi.service.customer;

import cn.psvmc.cxzapi.config.mybatisplus.service.impl.AbstractService;
import cn.psvmc.cxzapi.mapper.customer.TCustomerGoodsCollectMapper;
import cn.psvmc.cxzapi.model.customer.TCustomerGoodsCollect;
import cn.psvmc.cxzapi.service.system.ServiceUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 客户商品收藏表 服务实现类
 *
 * @Author auto
 * @Date 2024-08-27
 */
@Service
public class TCustomerGoodsCollectService extends AbstractService<TCustomerGoodsCollectMapper, TCustomerGoodsCollect> {

    @Resource
    private TCustomerGoodsCollectMapper tCustomerGoodsCollectMapper;
    @Resource
    private ServiceUtil serviceUtil;

    /**
     * @Description 收藏
     * @Date 2024/8/27 21:46
     * @Author YWX
     * @Param [tCustomerGoodsCollect]
     * @Return void
     **/
    public void add(TCustomerGoodsCollect tCustomerGoodsCollect) {
        Integer cgcid = tCustomerGoodsCollectMapper.findByCustomerIdAndGoodsId(serviceUtil.getCustomerId(), tCustomerGoodsCollect.getGoodsId());
        if (cgcid != null) {
            return;
        }
        tCustomerGoodsCollectMapper.insert(tCustomerGoodsCollect);
    }

    /**
     * @Description 取消收藏
     * @Date 2024/8/27 21:47
     * @Author YWX
     * @Param [id]
     * @Return void
     **/
    public void delete(Integer goodsId) {
        tCustomerGoodsCollectMapper.deleteByCustomerIdAndGoodsId(serviceUtil.getCustomerId(), goodsId);
    }

    /**
     * @Date auto 2024-08-27 查询客户商品收藏表列表
     * @Param iPage 分页
     * @Return com.baomidou.mybatisplus.core.metadata.IPage<cn.psvmc.cxzapi.model.customer.TCustomerGoodsCollect>
     */
    public IPage<Map<String, Object>> list(Page<TCustomerGoodsCollect> iPage) {
        return tCustomerGoodsCollectMapper.listByCustomerId(iPage, serviceUtil.getCustomerId());
    }

    /**
     * @Description 商品是否收藏
     * @Date 2024/9/5 21:46
     * @Author YWX
     * @Param [id]
     * @Return boolean
     **/
    public boolean isGoodsCollect(Integer id) {
        boolean rtn = false;
        Integer cgcid = tCustomerGoodsCollectMapper.findByCustomerIdAndGoodsId(serviceUtil.getCustomerId(), id);
        if (cgcid != null) {
            rtn = true;
        }
        return rtn;
    }
}
